﻿namespace IPTableAdapters
{
    using System;
    using System.CodeDom.Compiler;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Configuration;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using System.Diagnostics;

    [HelpKeyword("vs.data.TableAdapter"), DesignerCategory("code"), Designer("Microsoft.VSDesigner.DataSource.Design.TableAdapterDesigner, Microsoft.VSDesigner, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), GeneratedCode("System.Data.Design.TypedDataSetGenerator", "2.0.0.0"), ToolboxItem(true), DataObject(true)]
    public class SearchProjectTableAdapter : Component
    {
        private SqlDataAdapter _adapter;
        private bool _clearBeforeFill;
        private SqlCommand[] _commandCollection;
        private SqlConnection _connection;

        /*[DebuggerNonUserCode]*/
        public SearchProjectTableAdapter()
        {
            this.ClearBeforeFill = true;
        }

        /*[DebuggerNonUserCode]*/
        private void InitAdapter()
        {
            this._adapter = new SqlDataAdapter();
            DataTableMapping tableMapping = new DataTableMapping();
            tableMapping.SourceTable = "Table";
            tableMapping.DataSetTable = "SearchProject";
            tableMapping.ColumnMappings.Add("Project Code", "Project Code");
            tableMapping.ColumnMappings.Add("Client", "Client");
            tableMapping.ColumnMappings.Add("Country", "Country");
            tableMapping.ColumnMappings.Add("Type", "Type");
            tableMapping.ColumnMappings.Add("Agent", "Agent");
            tableMapping.ColumnMappings.Add("Title", "Title");
            tableMapping.ColumnMappings.Add("Applicant", "Applicant");
            tableMapping.ColumnMappings.Add("Responsible Person", "Responsible Person");
            tableMapping.ColumnMappings.Add("Status", "Status");
            tableMapping.ColumnMappings.Add("Inventor", "Inventor");
            this._adapter.TableMappings.Add(tableMapping);
        }

        /*[DebuggerNonUserCode]*/
        private void InitCommandCollection()
        {
            this._commandCollection = new SqlCommand[] { new SqlCommand() };
            this._commandCollection[0].Connection = this.Connection;
            this._commandCollection[0].CommandText = "SELECT     Project.ProjectCode AS [Project Code], ISNULL(Project.ClientName, N'') AS Client, ISNULL(Country.EnglishName, N'') AS Country, Project.Type, \r\n                      ISNULL(Project.Agent, N'') AS Agent, Project.Title, Project.Applicant, ISNULL(ProjectSupervisor.ResponsiblePerson, N'') AS [Responsible Person], \r\n                      Project.Status, Project.Inventor\r\nFROM         Project LEFT OUTER JOIN\r\n                      Country ON Project.Country = Country.Country LEFT OUTER JOIN\r\n                      ProjectSupervisor ON Project.ProjectCode = ProjectSupervisor.ProjectCode\r\n";
            this._commandCollection[0].CommandType = CommandType.Text;
        }

        /*[DebuggerNonUserCode]*/
        private void InitConnection()
        {
            this._connection = new SqlConnection();
            this._connection.ConnectionString = ConfigurationManager.ConnectionStrings["LocalSqlConnection1"].ConnectionString;
        }

        [HelpKeyword("vs.data.TableAdapter"), DebuggerNonUserCode, DataObjectMethod(DataObjectMethodType.Select, true)]
        public virtual IP.SearchProjectDataTable SearchProject()
        {
            this.Adapter.SelectCommand = this.CommandCollection[0];
            IP.SearchProjectDataTable dataTable = new IP.SearchProjectDataTable();
            this.Adapter.Fill(dataTable);
            return dataTable;
        }

        /*[DebuggerNonUserCode]*/
        private SqlDataAdapter Adapter
        {
            get
            {
                if (this._adapter == null)
                {
                    this.InitAdapter();
                }
                return this._adapter;
            }
        }

        /*[DebuggerNonUserCode]*/
        public bool ClearBeforeFill
        {
            get
            {
                return this._clearBeforeFill;
            }
            set
            {
                this._clearBeforeFill = value;
            }
        }

        /*[DebuggerNonUserCode]*/
        protected SqlCommand[] CommandCollection
        {
            get
            {
                if (this._commandCollection == null)
                {
                    this.InitCommandCollection();
                }
                return this._commandCollection;
            }
        }

        /*[DebuggerNonUserCode]*/
        internal SqlConnection Connection
        {
            get
            {
                if (this._connection == null)
                {
                    this.InitConnection();
                }
                return this._connection;
            }
            set
            {
                this._connection = value;
                if (this.Adapter.InsertCommand != null)
                {
                    this.Adapter.InsertCommand.Connection = value;
                }
                if (this.Adapter.DeleteCommand != null)
                {
                    this.Adapter.DeleteCommand.Connection = value;
                }
                if (this.Adapter.UpdateCommand != null)
                {
                    this.Adapter.UpdateCommand.Connection = value;
                }
                for (int i = 0; i < this.CommandCollection.Length; i++)
                {
                    if (this.CommandCollection[i] != null)
                    {
                        this.CommandCollection[i].Connection = value;
                    }
                }
            }
        }
    }
}

